<template>
  <el-form ref="form" :model="role" :rules="rules" label-width="100px" class="demo-ruleForm">
    <el-form-item label="角色名称" prop="name">
      <el-input v-model="role.name" />
    </el-form-item>
    <el-form-item label="说明" prop="remark">
      <el-input v-model="role.remark" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm()">提交</el-button>
      <el-button @click="resetForm()">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import axios from '@/utils/request'
export default {
  data() {
    return {
      role: {
        name: '',
        remark: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入角色名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 提交
    submitForm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          await axios({ url: '/roles', method: 'post', data: this.role })
          this.$emit('closeWin', true)
          this.resetForm()
        }
      })
    },
    // 重置
    resetForm() {
      this.$refs['form'].resetFields()
    }
  }
}
</script>
